<?php

Raise::load('core.helper.convert.RaiseAbstractConverter');
Raise::load('core.datetime.RaiseDateTime');

/**
 * RaiseDateTime Converter helper class
 * for conversion to RaiseDateTime
 * 
 * @author Sam-Mauris Yong / hellclanner at live dot com
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package phpraise.core.helper.convert.datatype
 * @since 1.2
 */
class RaiseDateTimeConverter extends RaiseAbstractConverter {
    
    /**
     * Convert the subject to RaiseDateTime
     * @param mixed $subject The subject to convert
     * @return RaiseDateTime The result
     */
    public function convert($subject) {
        if(RaiseVariable::isType($subject, RaiseVariable::TYPESTRING)){
            return RaiseDateTime::fromString($subject);
        }elseif(RaiseVariable::isType($subject, RaiseVariable::TYPEINTEGER)){
            return RaiseDateTime::fromTimestamp($subject);
        }elseif($subject instanceof RaiseDateTime){
            return $subject;
        }
        return RaiseDateTime::now();
    }
    
}